package ua.cs.stu.ics.GUI;

import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.LayoutManager;
import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

public class ImagePanel extends JPanel {

    BufferedImage image;

    int w, h;

    public ImagePanel(String imag) {

        try {
            image = ImageIO.read(new File(imag));
            w = image.getWidth();
            h = image.getHeight();
            setBackground(Color.white);
        } catch (IOException ioe) {
            System.out.println(ioe);
        }
    }

    public Dimension getPreferredSize() {
        return new Dimension(w, h);
    }

    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(image, 0, 0, this);
    }
}